<template>
  <div class="user-manager">
    <!-- 页面标题区域 -->
    <div class="page-header">
      <h2>用户管理</h2>
      <el-tag type="info">共 {{ total }} 个用户</el-tag>
    </div>

    <!-- 搜索和操作区域 -->
    <el-card class="operation-area" shadow="hover">
      <el-form :inline="true" :model="searchForm" class="search-form">
        <el-form-item label="用户名">
          <el-input v-model="searchForm.username" placeholder="请输入用户名" clearable></el-input>
        </el-form-item>
        <el-form-item label="用户角色">
          <el-select v-model="searchForm.role" placeholder="请选择角色" clearable>
            <el-option
              v-for="option in roleOptions"
              :key="option.value"
              :label="option.label"
              :value="option.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="账号状态">
          <el-select v-model="searchForm.status" placeholder="请选择状态" clearable>
            <el-option label="启用" :value="1"></el-option>
            <el-option label="禁用" :value="0"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button size="medium" type="primary" @click="handleSearch" plain>查询</el-button>
          <el-button size="medium" @click="resetSearch" plain>重置</el-button>
        </el-form-item>
      </el-form>
      <div class="operation-buttons">
        <el-button  type="primary" plain size="medium" @click="handleAdd">
          <i class="el-icon-plus"></i> 新增用户
        </el-button>
        <el-button plain size="medium" @click="getList">
          <i class="el-icon-refresh"></i> 刷新
        </el-button>
      </div>
    </el-card>

    <!-- 数据统计卡片 -->
    <div class="statistics-cards">
      <el-row :gutter="20">
        <el-col :span="6">
          <el-card shadow="hover" class="stat-card">
            <div class="stat-content">
              <div class="stat-left">
                <div class="stat-icon"><i class="el-icon-user"></i></div>
                <div class="stat-title">普通用户</div>
              </div>
              <div class="stat-value">{{ statistics.normalUsers || 0 }}</div>
            </div>
          </el-card>
        </el-col>
        <el-col :span="6">
          <el-card shadow="hover" class="stat-card">
            <div class="stat-content">
              <div class="stat-left">
                <div class="stat-icon"><i class="el-icon-s-shop"></i></div>
                <div class="stat-title">商户用户</div>
              </div>
              <div class="stat-value">{{ statistics.merchants || 0 }}</div>
            </div>
          </el-card>
        </el-col>
        <el-col :span="6">
          <el-card shadow="hover" class="stat-card">
            <div class="stat-content">
              <div class="stat-left">
                <div class="stat-icon"><i class="el-icon-s-custom"></i></div>
                <div class="stat-title">管理员</div>
              </div>
              <div class="stat-value">{{ statistics.admins || 0 }}</div>
            </div>
          </el-card>
        </el-col>
        <el-col :span="6">
          <el-card shadow="hover" class="stat-card">
            <div class="stat-content">
              <div class="stat-left">
                <div class="stat-icon"><i class="el-icon-warning-outline"></i></div>
                <div class="stat-title">禁用账号</div>
              </div>
              <div class="stat-value">{{ statistics.disabled || 0 }}</div>
            </div>
          </el-card>
        </el-col>
      </el-row>
    </div>

    <!-- 用户列表 -->
    <el-card class="table-card" shadow="hover">
      <el-table :data="users" v-loading="listLoading" border style="width: 100%">
        <el-table-column prop="id" label="ID" width="80" align="center"></el-table-column>
        <el-table-column prop="username" label="用户名" min-width="120"></el-table-column>
        <el-table-column prop="name" label="真实姓名" min-width="120"></el-table-column>
        <el-table-column prop="email" label="邮箱" min-width="180"></el-table-column>
        <el-table-column prop="balance" label="账户余额" width="120">
          <template slot-scope="scope">
            <span>¥{{ scope.row.balance ? scope.row.balance.toFixed(2) : '0.00' }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="role" label="角色" width="120">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.role === 'SUPER_ADMIN'" type="danger">超级管理员</el-tag>
            <el-tag v-else-if="scope.row.role === 'ADMIN'" type="warning">管理员</el-tag>
            <el-tag v-else-if="scope.row.role === 'MERCHANT'" type="success">商户</el-tag>
            <el-tag v-else type="info">普通用户</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="status" label="状态" width="100" align="center">
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.status"
              :active-value="1"
              :inactive-value="0"
              @change="handleStatusChange(scope.row)"
              active-color="#13ce66"
              inactive-color="#ff4949">
            </el-switch>
          </template>
        </el-table-column>
        <el-table-column label="创建时间" width="180">
          <template slot-scope="scope">
            {{ scope.row.createdAt | formatDate }}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="250" fixed="right" align="center">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="handleEdit(scope.row)">
              <i class="el-icon-edit"></i> 编辑
            </el-button>
            <el-button type="text" size="small" class="delete-btn" @click="handleDelete(scope.row)">
              <i class="el-icon-delete"></i> 删除
            </el-button>
            <el-button 
              v-if="scope.row.role === 'MERCHANT'" 
              type="text" 
              size="small" 
              @click="handleViewLicense(scope.row)">
              <i class="el-icon-picture-outline"></i> 查看执照
            </el-button>
            <el-button 
              type="text" 
              size="small" 
              @click="handleAdjustBalance(scope.row)">
              <i class="el-icon-wallet"></i> 调整余额
            </el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.currentPage"
        :limit.sync="queryParams.size"
        @pagination="getList"
      />
    </el-card>

    <!-- 用户表单对话框 -->
    <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="500px" :close-on-click-modal="false">
      <el-form :model="form" :rules="rules" ref="form" label-width="100px">
        <el-form-item label="用户名" prop="username">
          <el-input v-model="form.username" placeholder="请输入用户名" :disabled="dialogMode === 'edit'"></el-input>
        </el-form-item>
        <el-form-item label="真实姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入真实姓名"></el-input>
        </el-form-item>
        <el-form-item label="邮箱" prop="email">
          <el-input v-model="form.email" placeholder="请输入邮箱"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password" v-if="dialogMode === 'add'">
          <el-input v-model="form.password" type="password" placeholder="请输入密码"></el-input>
        </el-form-item>
        <el-form-item label="用户角色" prop="role">
          <el-select v-model="form.role" placeholder="请选择角色" style="width: 100%;">
            <el-option
              v-for="option in roleOptions"
              :key="option.value"
              :label="option.label"
              :value="option.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="账号状态" prop="status">
          <el-switch
            v-model="form.status"
            :active-value="1"
            :inactive-value="0"
            active-text="启用"
            inactive-text="禁用">
          </el-switch>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="submitForm">确 定</el-button>
      </div>
    </el-dialog>

    <!-- 营业执照预览对话框 -->
    <el-dialog title="营业执照预览" :visible.sync="licenseDialogVisible" width="500px">
      <div  style="min-height: 200px;">
        <div class="license-preview" v-if="currentLicense">
          <img 
            :src="'/api' + currentLicense" 
            alt="营业执照" 
            class="license-image"
           
            @error="handleImageError"
          >
        </div>
        <div v-else class="no-license">
          <i class="el-icon-picture-outline"></i>
          <p>暂未上传营业执照</p>
        </div>
      </div>
    </el-dialog>

    <!-- 添加余额调整对话框 -->
    <el-dialog title="调整余额" :visible.sync="balanceDialogVisible" width="400px">
      <div class="balance-dialog-content">
        <div class="user-info">
          <div class="info-item">
            <span class="label">用户名:</span>
            <span class="value">{{ currentUser?.username }}</span>
          </div>
          <div class="info-item">
            <span class="label">当前余额:</span>
            <span class="value balance">¥{{ currentUser?.balance ? currentUser.balance.toFixed(2) : '0.00' }}</span>
          </div>
        </div>
        
        <el-form :model="balanceForm" :rules="balanceRules" ref="balanceForm" label-width="100px" class="balance-form">
          <el-form-item label="操作类型" prop="operationType">
            <el-radio-group v-model="balanceForm.operationType">
              <el-radio :label="'add'">增加余额</el-radio>
              <el-radio :label="'subtract'">减少余额</el-radio>
              <el-radio :label="'set'">设置余额</el-radio>
            </el-radio-group>
          </el-form-item>
          
          <el-form-item label="金额" prop="amount">
            <el-input-number 
              v-model="balanceForm.amount" 
              :min="0.01" 
              :precision="2" 
              :step="100"
              style="width: 200px;"
            ></el-input-number>
          </el-form-item>
          
          <el-form-item label="备注" prop="remark">
            <el-input 
              type="textarea" 
              v-model="balanceForm.remark"
              :rows="3"
              placeholder="请输入操作备注（可选）"
            ></el-input>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="balanceDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="submitBalanceAdjustment">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import Request from '@/utils/request'
import Pagination from '@/components/Pagination/index.vue'

export default {
  name: 'UserManager',
  components: { Pagination },
  inject: ['userInfo'],
  data() {
    // 邮箱验证规则
    const validateEmail = (rule, value, callback) => {
      const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
      if (!value) {
        callback(new Error('请输入邮箱地址'))
      } else if (!emailRegex.test(value)) {
        callback(new Error('请输入正确的邮箱地址'))
      } else {
        callback()
      }
    }

    return {
      // 搜索表单
      searchForm: {
        username: '',
        role: '',
        status: ''
      },
      // 查询参数
      queryParams: {
        currentPage: 1,
        size: 10
      },
      // 用户列表
      users: [],
      // 总数
      total: 0,
      // 加载状态
      listLoading: false,
      // 对话框显示
      dialogVisible: false,
      // 对话框标题
      dialogTitle: '',
      // 对话框模式
      dialogMode: 'add',
      // 表单数据
      form: {
        username: '',
        name: '',
        email: '',
        password: '',
        role: '',
        status: 1
      },
      // 统计数据
      statistics: {
        normalUsers: 0,
        merchants: 0,
        admins: 0,
        superAdmins: 0,
        disabled: 0,
        totalUsers: 0,
        todayRegistered: 0
      },
      // 表单校验规则
      rules: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' },
          { min: 3, max: 20, message: '长度在 3 到 20 个字符', trigger: 'blur' }
        ],
        name: [
          { required: true, message: '请输入真实姓名', trigger: 'blur' }
        ],
        email: [
          { required: true, validator: validateEmail, trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 6, message: '密码长度不能小于6位', trigger: 'blur' }
        ],
        role: [
          { required: true, message: '请选择用户角色', trigger: 'change' }
        ]
      },
      // 添加当前用户角色相关数据
      currentRole: '',
      roleOptions: [], // 动态角色选项
      licenseDialogVisible: false,
      currentLicense: '',
      imageLoading: false,
      // 余额调整相关
      balanceDialogVisible: false,
      currentUser: null,
      balanceForm: {
        operationType: 'add',
        amount: 100,
        remark: ''
      },
      balanceRules: {
        operationType: [
          { required: true, message: '请选择操作类型', trigger: 'change' }
        ],
        amount: [
          { required: true, message: '请输入金额', trigger: 'blur' },
          { type: 'number', min: 0.01, message: '金额必须大于0', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.currentRole = this.userInfo.role
    this.initRoleOptions()
    this.getList()
    this.getStatistics()
  },
  methods: {
    // 初始化角色选项
    initRoleOptions() {
      switch (this.currentRole) {
        case 'SUPER_ADMIN':
          this.roleOptions = [
            { label: '管理员', value: 'ADMIN' },
            { label: '商户', value: 'MERCHANT' },
            { label: '普通用户', value: 'USER' }
          ]
          break
        case 'ADMIN':
          this.roleOptions = [
            { label: '商户', value: 'MERCHANT' },
            { label: '普通用户', value: 'USER' }
          ]
          break
        default:
          this.roleOptions = []
      }
    },

    // 获取用户列表
    async getList() {
      this.listLoading = true
      try {
        const params = {
          ...this.queryParams,
          ...this.searchForm
        }
        const res = await Request.get('/user/page', { params })
        if (res.code === '0') {
          // 修改用户列表过滤逻辑
          this.users = res.data.records.filter(user => {
            // 超级管理员可以看到除了超级管理员之外的所有用户
            if (this.currentRole === 'SUPER_ADMIN') {
              return user.role !== 'SUPER_ADMIN'
            } 
            // 管理员可以看到普通用户和商户
            else if (this.currentRole === 'ADMIN') {
              return ['USER', 'MERCHANT'].includes(user.role)
            }
            return false
          })
          // 使用后端返回的总数，而不是过滤后的长度
          this.total = res.data.total
        }
      } catch (error) {
        console.error('获取用户列表失败:', error)
        this.$message.error('获取用户列表失败')
      } finally {
        this.listLoading = false
      }
    },

    // 搜索
    handleSearch() {
      this.queryParams.currentPage = 1
      this.getList()
      this.getStatistics() // 刷新统计数据
    },

    // 重置搜索
    resetSearch() {
      this.searchForm = {
        username: '',
        role: '',
        status: ''
      }
      this.handleSearch()
    },

    // 新增用户
    handleAdd() {
      this.dialogMode = 'add'
      this.dialogTitle = '新增用户'
      this.form = {
        username: '',
        name: '',
        email: '',
        password: '',
        role: '',
        status: 1
      }
      this.dialogVisible = true
    },

    // 编辑用户
    handleEdit(row) {
      // 检查权限
      if (this.currentRole === 'ADMIN' && (row.role === 'SUPER_ADMIN' || row.role === 'ADMIN')) {
        this.$message.error('没有权限编辑该用户')
        return
      }
      
      this.dialogMode = 'edit'
      this.dialogTitle = '编辑用户'
      this.form = { ...row }
      delete this.form.password
      this.dialogVisible = true
    },

    // 删除用户
    handleDelete(row) {
      // 检查权限
      if (this.currentRole === 'ADMIN' && (row.role === 'SUPER_ADMIN' || row.role === 'ADMIN')) {
        this.$message.error('没有权限删除该用户')
        return
      }

      this.$confirm('确认删除该用户?', '提示', {
        type: 'warning'
      }).then(async () => {
        try {
          const res = await Request.delete(`/user/delete/${row.id}`)
          if (res.code === '0') {
            this.$message.success('删除成功')
            this.getList()
          }else{
            this.$message.error(res.msg || '删除失败')
          }
        } catch (error) {
          console.error('删除用户失败:', error)
        }
      }).catch(() => {})
    },

    // 更改用户状态
    async handleStatusChange(row) {
      // 检查权限
      if (this.currentRole === 'ADMIN' && (row.role === 'SUPER_ADMIN' || row.role === 'ADMIN')) {
        this.$message.error('没有权限修改该用户状态')
        row.status = row.status === 1 ? 0 : 1 // 恢复状态
        return
      }

      try {
        const res = await Request.put(`/user/${row.id}`, {
          status: row.status
        })
        if (res.code === '0') {
          this.$message.success('状态更新成功')
        } else {
          row.status = row.status === 1 ? 0 : 1
          this.$message.error('状态更新失败')
        }
      } catch (error) {
        row.status = row.status === 1 ? 0 : 1
        console.error('更新用户状态失败:', error)
        this.$message.error('更新失败')
      }
    },

    // 提交表单
    submitForm() {
      this.$refs.form.validate(async (valid) => {
        if (valid) {
          try {
            const method = this.dialogMode === 'add' ? 'post' : 'put'
            const url = this.dialogMode === 'add' ? '/user/add' : `/user/${this.form.id}`
            
            // 添加加载状态
            this.$loading({
              lock: true,
              text: '提交中...',
              spinner: 'el-icon-loading'
            })
            
            const res = await Request[method](url, this.form)
            
            if (res.code === '0') {
              this.$message.success(`${this.dialogMode === 'add' ? '添加' : '更新'}成功`)
              this.dialogVisible = false
              this.getList()
            } else {
              // 处理后端返回的错误
              this.$message.error(res.msg || '操作失败')
            }
          } catch (error) {
            console.error('提交表单失败:', error)
            this.$message.error(error.response?.data?.msg || '操作失败，请稍后重试')
          } finally {
            // 关闭加载状态
            this.$loading().close()
          }
        } else {
          // 表单验证失败
          this.$message.warning('请填写完整所有必填项')
          return false
        }
      })
    },

    handleViewLicense(row) {
      this.imageLoading = true;
      this.currentLicense = row.businessLicense;
      this.licenseDialogVisible = true;
    },
    
    handleImageError() {
      this.imageLoading = false;
      this.$message.error('图片加载失败');
    },

    // 添加调整余额方法
    handleAdjustBalance(user) {
      this.currentUser = JSON.parse(JSON.stringify(user));
      this.balanceForm = {
        operationType: 'add',
        amount: 100,
        remark: ''
      };
      this.balanceDialogVisible = true;
    },

    // 提交余额调整
    async submitBalanceAdjustment() {
      try {
        await this.$refs.balanceForm.validate();
        
        const userId = this.currentUser.id;
        const { operationType, amount } = this.balanceForm;
        
        let res;
        
        if (operationType === 'add') {
          // 增加余额
          res = await Request.post(`/user/balance/recharge/${userId}?amount=${amount}`);
        } else if (operationType === 'subtract') {
          // 减少余额
          if (this.currentUser.balance < amount) {
            this.$message.error('用户余额不足，无法扣减');
            return;
          }
          res = await Request.post(`/user/balance/deduct/${userId}?amount=${amount}`);
        } else if (operationType === 'set') {
          // 设置余额为指定值
          // 先将余额清零
          if (this.currentUser.balance > 0) {
            await Request.post(`/user/balance/deduct/${userId}?amount=${this.currentUser.balance}`);
          }
          // 再设置为新值
          if (amount > 0) {
            res = await Request.post(`/user/balance/recharge/${userId}?amount=${amount}`);
          } else {
            res = { code: '0' };
          }
        }
        
        if (res.code === '0') {
          this.$message.success('余额调整成功');
          this.balanceDialogVisible = false;
          this.getList(); // 刷新列表
        } else {
          this.$message.error(res.msg || '余额调整失败');
        }
      } catch (error) {
        console.error('余额调整失败:', error);
        this.$message.error('余额调整失败');
      }
    },

    // 获取用户统计数据
    async getStatistics() {
      try {
        const res = await Request.get('/user/statistics')
        if (res.code === '0') {
          this.statistics = res.data
        } else {
          console.error('获取用户统计数据失败:', res.msg)
        }
      } catch (error) {
        console.error('获取用户统计数据失败:', error)
      }
    },
  },
  filters: {
    formatDate(timestamp) {
      if (!timestamp) return ''
      const date = new Date(timestamp)
      return date.toLocaleString()
    }
  }
}
</script>

<style lang="less" scoped>
.user-manager {
  padding: 24px;
  background-color: #fff8f0;
  min-height: calc(100vh - 60px);
  animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.page-header {
  display: flex;
  align-items: center;
  margin-bottom: 24px;

  h2 {
    font-size: 24px;
    font-weight: 500;
    color: #E67E22;
    margin: 0;
    margin-right: 15px;
  }
}

.operation-area {
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.05);
  margin-bottom: 24px;
}

.search-form {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

.statistics-cards {
  margin-bottom: 24px;
  position: relative;
}

.stat-card {
  border-radius: 12px;
  transition: all 0.3s;
  border: none;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.05);
}

.stat-card:hover {
  box-shadow: 0 6px 20px rgba(243, 156, 18, 0.1);
  transform: none;
}

.stat-content {
  padding: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(to right, #fff, #fff8e6);
  position: relative;
  overflow: hidden;
}

.stat-content::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: linear-gradient(to bottom, #F39C12, rgba(243, 156, 18, 0.5));
}

.stat-left {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-start;
}

.stat-icon {
  font-size: 26px;
  color: #F39C12;
  opacity: 0.8;
  text-align: center;
  background-color: rgba(243, 156, 18, 0.1);
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
}

.stat-title {
  font-size: 14px;
  color: #606266;
  font-weight: 500;
}

.stat-value {
  font-size: 24px;
  font-weight: 600;
  color: #E67E22;
  margin-right: 16px;
}

.table-card {
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.05);
  overflow: hidden;
}

.operation-buttons {
  margin-top: 20px;
  display: flex;
  gap: 12px;
}

:deep(.el-table) {
  border-radius: 8px;
  overflow: hidden;
  box-shadow: none;
}

:deep(.el-table th) {
  background-color: #fff4e0;
  font-weight: 500;
  color: #E67E22;
  padding: 14px 0;
}

:deep(.el-table td) {
  padding: 14px 0;
}

:deep(.el-table--striped .el-table__body tr.el-table__row--striped td) {
  background-color: #fffbf5;
}

.delete-btn {
  color: #f56c6c;
  margin-left: 12px;

  &:hover {
    color: #ff4949;
  }
}

/* 美化对话框 */
:deep(.el-dialog) {
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
}

:deep(.el-dialog__header) {
  padding: 24px;
  border-bottom: 1px solid #f5e8d3;
  margin: 0;
  background: #fff4e0;
}

:deep(.el-dialog__title) {
  font-size: 20px;
  font-weight: 500;
  color: #E67E22;
}

:deep(.el-dialog__body) {
  padding: 32px 24px;
}

:deep(.el-dialog__footer) {
  padding: 16px 24px;
  border-top: 1px solid #f5e8d3;
  background: #faf7f0;
}

/* 美化表单 */
:deep(.el-form-item__label) {
  font-weight: 500;
  color: #E67E22;
}

:deep(.el-input__inner) {
  border-radius: 8px;
  border: 1px solid #f0d5b3;
  transition: all 0.3s;
  padding: 0 15px;
  height: 40px;
  line-height: 40px;
}

:deep(.el-input__inner:focus) {
  border-color: #F39C12;
  box-shadow: 0 0 0 2px rgba(243, 156, 18, 0.2);
}

:deep(.el-select .el-input__inner:focus) {
  border-color: #F39C12;
}

:deep(.el-button--primary) {
  background-color: #F39C12;
  border-color: #F39C12;
  color: #fff;
}

:deep(.el-button--primary:hover) {
  background-color: #E67E22;
  border-color: #E67E22;
  color: #fff;
}

:deep(.el-button--text) {
  color: #F39C12;
}

.license-preview {
  text-align: center;
  background-color: #fff4e0;
  padding: 20px;
  border-radius: 8px;

  .license-image {
    width: 100%;
    max-width: 420px; /* A4 比例 */
    height: 594px; /* 保持 1:1.414 的比例 */
    object-fit: contain;
    background-color: #fff4e0;
    border: 1px solid #f0d5b3;
    border-radius: 4px;
  }
}

.no-license {
  text-align: center;
  padding: 60px 0;
  background-color: #fff4e0;
  border-radius: 8px;
  color: #909399;

  i {
    font-size: 48px;
    margin-bottom: 16px;
  }

  p {
    margin: 0;
    font-size: 14px;
  }
}

.balance-dialog-content {
  padding: 20px;
}

.user-info {
  margin-bottom: 20px;
}

.info-item {
  margin-bottom: 10px;
}

.label {
  font-weight: 500;
  color: #909399;
}

.value {
  margin-left: 10px;
}

.balance {
  color: #f56c6c;
  font-weight: 500;
}

.balance-form {
  margin-top: 20px;
}

/* 分页样式 */
:deep(.el-pagination) {
  padding: 20px 0;
  text-align: right;
}

:deep(.el-pagination button) {
  background: none;
}

:deep(.el-pagination .btn-next),
:deep(.el-pagination .btn-prev) {
  border: 1px solid #f0d5b3;
  border-radius: 8px;
}

:deep(.el-pager li) {
  border-radius: 8px;
  margin: 0 3px;
}

:deep(.el-pager li.active) {
  background-color: #F39C12;
  color: #fff;
}

:deep(.el-tag--info) {
  background-color: rgba(243, 156, 18, 0.1);
  border-color: rgba(243, 156, 18, 0.2);
  color: #F39C12;
}

:deep(.el-button) {
  border-radius: 8px;
  padding: 10px 20px;
  font-weight: 500;
  transition: all 0.3s;
}

:deep(.el-button:hover) {
  transform: none;
  box-shadow: none;
}

:deep(.el-switch.is-checked .el-switch__core) {
  border-color: #F39C12;
  background-color: #F39C12;
}
</style>